package com.gack.business.service;

import java.util.Date;
import java.util.List;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gack.business.model.AdvertisingPush;
import com.gack.business.repository.AdvertisingPushRepository;
import com.gack.helper.common.abstractobj.Result;

@Service
public class AdvertisingPushService implements AdvertisingPushServiceInterface {
	
	@Autowired
	private AdvertisingPushRepository advertisingPushRepository;
	
	@Transactional
	@Override
	public Result saveOrUpdate(List<AdvertisingPush> advertisingPushs) {
		for (AdvertisingPush advertisingPush : advertisingPushs) {
			advertisingPush.setCreateTime(new Date());
		}
		advertisingPushRepository.save(advertisingPushs);
		Result result = new Result();
		result.setKey("success");
		result.setValue("保存成功");
		return result;
	}

	@Override
	public Result getAdvertisingPuth() {
		Result result = new Result();
		result.setKey("success");
		result.setValue(advertisingPushRepository.findByPushSwitch("1"));
		return result;
	}
	@Override
	public Result getAllPush() {
		Result result = new Result();
		result.setKey("success");
		result.setValue(advertisingPushRepository.findAll());
		return result;
	}

}
